package org.zzz.controller;

import org.zzz.entity.Class;
import org.zzz.service.ClassService;
import org.zzz.service.impl.ClassServiceImpl;
import org.zzz.utils.Result;

import java.util.List;

/**
 * @Author ZZF
 * @Time 2021/04/20 22:56
 */
public class ClassController {
    private ClassService classService = new ClassServiceImpl();;

    /**
     * 获取所有班级
     * @return
     */
    public Result<List<Class>> listClass(){
        List<Class> classList = classService.listClass();
        return !classList.isEmpty() ? Result.success("查询成功").data(classList) : Result.error("暂无数据");
    }

    /**
     * 根据班级id获取班级
     * @param id
     * @return
     */
    public Result<String> getClassById(String id){
        Class classById = classService.getClassById(id);
        return classById != null ? Result.success("查询成功").data(classById) : Result.error("无此数据");
    }


    /**
     * 添加班级
     * @param classObject
     * @return
     */
    public Result addClass(Class classObject){
        return classService.insertClass(classObject) == true ? Result.success("添加成功") : Result.error("添加失败");
    }

    /**
     * 修改班级
     * @param classObject
     * @return
     */
    public Result updateClass(Class classObject){
        return classService.updateClass(classObject) == true ? Result.success("修改成功") : Result.error("修改失败");
    }

    /**
     * 根据班级id删除班级
     * @param id
     * @return
     */
    public Result deleteClass(String id){
        return classService.deleteClassById(id) == true ? Result.success("删除成功") : Result.error("删除失败");
    }

}
